package com.lanswon.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanswon.common.enums.ArticleStatus;
import com.lanswon.entity.ArticleVO;
import com.lanswon.entity.CommonProblem;
import com.lanswon.service.CommonProblemService;

/**
 * 常见问题
 * @author zj
 */
@Controller
@RequestMapping("front/problem/")
public class CommonProblemController {
	
	@Autowired
	private CommonProblemService commonProblemService;
	
	@RequestMapping("index/{problemType}")
	public String index(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap,
			@PathVariable("problemType") Integer problemType) {
		
		modelMap.addAttribute("problemType", problemType);
		
		return "front/problem/index";
	}
	
	@RequestMapping("cpDetail/{problemType}")
	@ResponseBody
	public Map<String, Object> aboutsmkDetail(HttpServletRequest request,HttpServletResponse response,
			@PathVariable("problemType") Integer problemType){
		Map<String, Object> viewMap = new HashMap<>();
		try {
			
			Map<String, Object> accessMap = new HashMap<>();
			accessMap.put("problemType", problemType);
			List<CommonProblem> pageList = commonProblemService.findCommonProblemByCondition(accessMap);
			viewMap.put("commonProblem", pageList!=null&&pageList.size()>0?pageList.get(0):null);
			viewMap.put("code", 0);
			viewMap.put("message", "查询成功");
			viewMap.put("problemType", problemType);
		} catch (Exception e) {
			e.printStackTrace();
			viewMap.put("code", 2);
			viewMap.put("message", "查询失败");
		}
		return viewMap;
	}
	
}
